home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dd / commands.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  47KB  |  1,747 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. #include    "defs.h"
  7. #include    "dbug_protos.h"
  8.  
  9.  
  10. Prototype void        RefreshFKeys(BOOL fullRefresh);
  11. Prototype BOOL        FunctionKey(UWORD num);
  12. Prototype BOOL        HelpKey(void);
  13.  
  14. Prototype BOOL         CmdFKey(char *args);
  15. Prototype BOOL        CmdRexx(char *args);
  16. Prototype BOOL        CmdSavePrefs(char *args);
  17. Prototype BOOL        CmdInfo(char *args);
  18. Prototype BOOL        CmdExecBase(char *args);
  19. Prototype BOOL        CmdResources(char *args);
  20. Prototype BOOL        CmdIntrs(char *args);
  21. Prototype BOOL        CmdPorts(char *args);
  22. Prototype BOOL        CmdSymList(char *args);
  23. Prototype BOOL        CmdTasks(char *args);
  24. Prototype BOOL        CmdLibs(char *args);
  25. Prototype BOOL        CmdDevices(char *args);
  26. Prototype BOOL        CmdMemList(char *args);
  27. Prototype BOOL        CmdDoBsBase(char *args);
  28. Prototype BOOL        CmdProcess(char *args);
  29. Prototype BOOL        CmdOffsets(char *args);
  30. Prototype BOOL        CmdDown(char *args);
  31. Prototype BOOL        CmdUp(char *args);
  32. Prototype BOOL        CmdPageDown(char *args);
  33. Prototype BOOL        CmdPageUp(char *args);
  34. Prototype BOOL        CmdSource(char *args);
  35. Prototype BOOL        CmdDism(char *args);
  36. Prototype BOOL        CmdMixed(char *args);
  37. Prototype BOOL        CmdBytes(char *args);
  38. Prototype BOOL        CmdWords(char *args);
  39. Prototype BOOL        CmdLongs(char *args);
  40. Prototype BOOL        CmdBreakpoint(char *args);
  41. Prototype BOOL        CmdBP(char *args);
  42. Prototype BOOL        CmdClear(char *args);
  43. Prototype BOOL        CmdHunks(char *args);
  44. Prototype BOOL        CmdSymbol(char *args);
  45. Prototype BOOL        CmdSet(char *args);
  46. Prototype BOOL        RStepTarget(void);
  47. Prototype BOOL        StepTarget(void);
  48. Prototype BOOL        StepTargetRange(ULONG addressLow, ULONG addressHi);
  49. Prototype BOOL        RStepTargetRange(ULONG addressLow, ULONG addressHi);
  50. Prototype BOOL        CmdStep(char *args);
  51. Prototype BOOL        CmdRStep(char *args);
  52. Prototype BOOL        OverTarget(void);
  53. Prototype BOOL        OverTargetRange(ULONG addressLow, ULONG addressHi);
  54. Prototype BOOL        CmdOver(char *args);
  55. Prototype BOOL        CmdReset(char *args);
  56. Prototype BOOL        GoTarget(void);
  57. Local void        CopyLastState(void);
  58. Prototype BOOL        CmdGo(char *args);
  59. Prototype BOOL        CmdEval(char *args);
  60. Prototype BOOL        CmdOpen(char *args);
  61. Prototype BOOL        CmdClose(char *args);
  62. Prototype BOOL        CmdQuit(char *args);
  63. Prototype BOOL        CmdHelp(char *args) ;
  64. Prototype BOOL        CmdWatchBytes(char *args);
  65. Prototype BOOL        CmdWatchWords(char *args);
  66. Prototype BOOL        CmdWatchLongs(char *args);
  67. Prototype BOOL        CmdWatchClear(char *args);
  68. Prototype BOOL        CmdRefresh(char *args);
  69. Prototype BOOL        CmdDosBase(char *args);
  70. Prototype WORD        RefreshHelp(WORD maxLines, BOOL fullRefresh, LONG);
  71. Prototype BOOL        DownHelp(void);
  72. Prototype BOOL        UpHelp(void);
  73. Prototype int        HelpSize(void);
  74. Prototype char        *SkipBlanks(char *s);
  75. Prototype BOOL        DoCommand(char *command);
  76. Prototype BOOL        CmdAlias(char *args);
  77. Prototype BOOL        CmdUnAlias(char *args);
  78. Prototype BOOL        CmdRegs(char *args);
  79. Prototype BOOL        CmdJump(char *args);
  80. Prototype BOOL         CmdBar(char *args);
  81. Prototype BOOL         CmdEnd(char *args);
  82. Prototype BOOL         CmdItem(char *args);
  83. Prototype BOOL         CmdTitle(char *args);
  84. Prototype BOOL         CmdMenus(char *args);
  85. Prototype BOOL         CmdSubItem(char *args);
  86. Prototype BOOL         CmdChangeWindow(char *args);
  87. Prototype BOOL         CmdAgain(char *args);
  88. Local       void         ShortStatus(int mode, char *command);
  89. Prototype void         init_function_keys(void);
  90.  
  91. // ************
  92.  
  93. typedef struct CMDDEF {
  94.     char    *helpText;
  95.     char    *command;
  96.     UWORD    commandLen;
  97.     BOOL    (*func)(char *args);
  98. } CMDDEF;
  99.  
  100.  
  101. CMDDEF    commandTable[] = {
  102.     // NOTE: These must be in alphabetical order
  103.     { "again            - repeat last command",            "AGAIN", 5, CmdAgain },
  104.     { "alias            - replace command with arexx script",    "ALIAS", 5, CmdAlias },
  105.     { "bp {expr}        - set breakpoint at expression",            "BP",          2, CmdBP },
  106.     { "bp ALL           - set all breakpoints in table",            "BP",          2, CmdBP },
  107.     { "breakpoints      - display breakpoint table",                "BREAKPOINTS", 11, CmdBreakpoint },
  108.     { "bytes {expr}     - display bytes {at expression}",           "BYTES",        5, CmdBytes },
  109.     { "changewindow     - move/size current window",              "CHANGEWINDOW",        12, CmdChangeWindow },
  110.     { "clear expr       - clear breakpoint at expression",          "CLEAR",        5, CmdClear },
  111.     { "clear ALL        - clear all breakpoints in table",          "CLEAR",        5, CmdClear },
  112.     { "close            - close a display",                         "CLOSE",        5, CmdClose },
  113.     { "devs             - display Exec Device List",                "DEVS",      4, CmdDevices },
  114.     { "dism {expr}      - change to dism mode {at expression}",     "DISM",         4, CmdDism },
  115.     { "dosbase          - intelligent display of DOSBase struct",   "DOSBASE",      7, CmdDosBase },
  116.     { "down             - move display down one line",              "DOWN",         4, CmdDown },
  117.     { "eval {expr}      - evaluate an expression",                  "EVAL",         4, CmdEval },
  118.     { "execbase         - display ExecBase (SysBase)",              "EXECBASE",     8, CmdExecBase },
  119.     { "fkey             - set function key definition",             "FKEY",     4, CmdFKey },
  120.     { "go {expr...}     - set {expr...} temp breakpoints & go",     "GO",           2, CmdGo  },
  121.     { "help             - online help",                        "HELP",         4, CmdHelp },
  122.     { "hunks            - change to hunks mode",                    "HUNKS",        5, CmdHunks },
  123.     { "info             - display ThisTask info",                   "INFO",         4, CmdInfo },
  124.     { "intrs            - display Exec Intrs List",                 "INTRS",        5, CmdIntrs },
  125.     { "jump {name}      - jump to public screen",                   "JUMP",        4, CmdJump },
  126.     { "libs             - display Exec Libs List",                  "LIBS",         4, CmdLibs },
  127.     { "longs {expr}     - display longs {at expression}",           "LONGS",        5, CmdLongs },
  128.     { "mbar slot        - add menu bar",                    "MBAR",   4, CmdBar },
  129.     { "mend slot        - add menu end mark",                "MEND",     4, CmdEnd },
  130.     { "memlist          - display Exec Mem List",                   "MEMLIST",      6, CmdMemList },
  131.     { "mitem {...}      - add menu item",                       "MITEM",   5, CmdItem },
  132.     { "mixed {expr}     - change to mixed mode {at expression}",    "MIXED",        5, CmdMixed },
  133.     { "menus            - activate a new set of user menus",        "MENUS", 5, CmdMenus },
  134.     { "msub {...}       - add a sub menu item",               "MSUB",   4, CmdSubItem },
  135.     { "mtitle {...}     - add menu title",                       "MTITLE",   6, CmdTitle },
  136.     { "offsets          - toggle display address/offsets",          "OFFSETS",      7, CmdOffsets },
  137.     { "open {type}      - open a new display",                      "OPEN",         4, CmdOpen },
  138.     { "over {expr}      - stepover one instruction or range",       "OVER",         4, CmdOver },
  139.     { "pagedown         - move display down one page",        "PAGEDOWN",         8, CmdPageDown },
  140.     { "pageup           - move display up one page",        "PAGEUP",         6, CmdPageUp },
  141.     { "rendlist         - end the arexx list",                   "RENDLIST",         8, RXEndList },    
  142.     { "rgetbyte {expr}  - get bytes at {expr}",                "RGETBYTE",         8, RXGetBytes },
  143.     { "rgetcom          - get command line input",            "RGETCOM",         7, RXGetCommand },
  144.     { "rgetdism {expr}  - get the dissembled line",                  "RGETDISM",         8, RXGetDismLine },
  145.     { "rgeteval {expr}  - evaluate the expression",                  "RGETEVAL",         8, RXGetEval },
  146.     { "rgetinfo {expr}  - get the program name and line number",      "RGETINFO",         8, RXGetInfo },
  147.     { "rgetline {expr}  - return the source/mixed line",              "RGETLINE",         8, RXGetLine },
  148.     { "rgetlong {expr}  - get longs at {expr}",                "RGETLONG",         8, RXGetLongs },
  149.     { "rgetword {expr}  - get words at {expr}",                "RGETWORD",         8, RXGetWords },
  150.     { "rgetpc           - return the program counter",                "RGETPC",         6, RXGetPC },
  151.     { "rputlist         - add an item to the arexx list",             "RPUTLIST",         8, RXPutList },    
  152.     { "rshowlist        - show the arexx list",               "RSHOWLIST",         9, RXEndList },    
  153.     { "rstartlist       - start the arexx list",               "RSTARTLIST",         10, RXStartList },    
  154.     { "rx rexx-script   - execute ARexx macro",                     "RX",         2, CmdRexx },
  155.     { "saveprefs        - save dd prefs to disk",                     "SAVEPREFS",    9, CmdSavePrefs },
  156.     { "set {addr} {val} - set address to val",                     "SET",    3, CmdSet },
  157.     { "ports            - display Exec Ports List",                 "PORTS",        5, CmdPorts },
  158.     { "process {expr}   - display process {at expression}",         "PROCESS",      7, CmdProcess },
  159.     { "resources        - display Exec Resource List",              "RESOURCES",    9, CmdResources },
  160.     { "quit             - _exit(20) & quit dd",                     "QUIT",         4, CmdQuit },
  161.     { "refresh          - refresh the window",                      "REFRESH",      7, CmdRefresh },
  162.     { "registers        - toggle the register display",             "REGISTERS",      9, CmdRegs },
  163.     { "reset            - _exit(20) & restart program",             "RESET",        5, CmdReset },
  164.     { "rstep            - toggle library call auto stepover flag",    "RSTEP",         5, CmdRStep },
  165.     { "source {expr}    - change to source mode {at expression}",   "SOURCE",       6, CmdSource },
  166.     { "step {expr}      - step program one instruction or range",   "STEP",         4, CmdStep },
  167.     { "symbols {expr}   - display symbol {at expr}",                "SYMBOLS",       7, CmdSymbol },
  168.     { "symlist          - display sorted symbol list",              "SYMLIST",       7, CmdSymList },
  169.     { "tasks            - display Exec Task Lists",                 "TASKS",        5, CmdTasks },
  170.     { "unalias          - restore command with arexx script",    "UNALIAS", 7, CmdUnAlias },
  171.     { "up               - move display up one line",                "UP",           2, CmdUp },
  172.     { "watchbyte {expr} - set/clear (toggle) byte watchpoints",     "WATCHBYTE",       9, CmdWatchBytes },
  173.     { "watchclear       - clear all watchpoints",             "WATCHCLEAR",       10, CmdWatchClear },
  174.         { "watchlong {expr} - set/clear (toggle) long watchpoints",     "WATCHLONG",       9, CmdWatchLongs },
  175.     { "watchword {expr} - set/clear (toggle) word watchpoints",     "WATCHWORD",       9, CmdWatchWords },
  176.     { "words {expr}     - display words {at expression}",           "WORDS",        5, CmdWords },
  177.     { "",                                                            NULL,           0, NULL }
  178. };
  179.  
  180. char    *HelpTable[] = {
  181.     "NOTES",
  182.     "MOUSE CLICK:",
  183.     "You can click the mouse on a label, register, or address",
  184.     "To apply it to the command line.  The operators displayed",
  185.     "in the command line are there for the express purpose of",
  186.     "clicking on them.  Clicking on '<' cancels a line, Clicking",
  187.     "on '>' executes it",
  188.     "",
  189.     "You can also click to the right of the command line to",
  190.     "execute the current command.  Function key equivalents",
  191.     "may be executed with a mouse click by clicking on the",
  192.     "number (e.g. the '4' in '4:bytes')",
  193.     "",
  194.     "EXPRESSION:",
  195.     "A C expression evaluator allowing parenthesis and most C",
  196.     "operators, including longword indirection with *",
  197.     "",
  198.     "Note that C constants are used, so hex values must be",
  199.     "preceeded by 0x, octal with 0, decimal by default.",
  200.     ""
  201. };
  202.  
  203.  
  204. // ************
  205.  
  206. char    *default_fkeys[10] = {
  207.     "source",
  208.     "mixed",
  209.     "dism",
  210.     "bytes",
  211.     "symbols",
  212.     "pc",
  213.     "step",
  214.     "over",
  215.     "reset",
  216.     "go"
  217. };
  218.  
  219. Prototype char    fkeys[10][16];
  220. char    fkeys[10][16];
  221.  
  222. void    RefreshFKeys(BOOL fullRefresh) {
  223.     UWORD    i;
  224.  
  225.     if(fullRefresh == -1) {
  226.     ScrPlain();
  227.     ScrRowCol(CurDisplay->ds_ScrRows, 2);
  228.     ScrDull();
  229.  
  230.     for (i=0; i<10; i++) {
  231.         ScrPrintf("%d:%s ", i+1, fkeys[i]);
  232.     }
  233.     ScrPlain();
  234.     ScrEOL();
  235.  
  236.     ScrFlush();
  237.     draw_fkey_boxes();
  238.     }
  239. }
  240.  
  241. void init_function_keys(void)
  242. {
  243. int i;
  244.     
  245.     memset((char *)fkeys,0,sizeof(fkeys));
  246.     for(i=0; i<10; i++)strcpy(fkeys[i],default_fkeys[i]);
  247. }
  248.  
  249.  
  250.  
  251.  
  252. BOOL    FunctionKey(UWORD num) {
  253.     if (num < 10) return DoCommand(fkeys[num]);
  254.     return 0;
  255. }
  256.  
  257. BOOL    HelpKey(void) {
  258.     return DoCommand("help");
  259. }
  260.  
  261.  
  262. BOOL CmdFKey(char *args) {
  263. char *ptr;
  264. int n;
  265.  
  266.     if(ptr = strchr(args,' ')) {    // if there is a slot
  267.     *ptr++ = NULL;
  268.     if(((n = strtol(args,NULL,10)) > 0) && (n <= 10))  {
  269.             if(*ptr) {    // and if there is a definition
  270.         strncpy(fkeys[n-1],ptr,16);
  271.         ScrStatus("Function key set");
  272.         RefreshFKeys(-1);
  273.         return TRUE;
  274.         }
  275.     }
  276.     }
  277.     ScrStatus("*** Can't set function key %d",n);
  278.     return FALSE;
  279. }
  280.  
  281. // ************
  282.  
  283. // Handle Rexx Command.  This routine looks in current directory, then
  284. // searches dcc:rexx/
  285.  
  286. BOOL    CmdRexx(char *arg) {
  287.     long    rc = 1;
  288.     char    *res;
  289.     long    ec;
  290.     char    buf[128];
  291.  
  292.     // don't add a . if they already have one
  293.     if(!strchr(arg,'.'))sprintf(buf, "%s.dd", arg);
  294.     else strcpy(buf, arg);
  295.  
  296.     rc = PlaceRexxCommand(NULL, buf, &res, &ec);
  297.     if (res) {
  298.         ScrStatus(res);
  299.         free(res);
  300.     }
  301.     if (ec || rc) {
  302.         // try in dcc:rexx
  303.         sprintf(buf, "dcc:rexx/%s.dd", arg);
  304.         rc = PlaceRexxCommand(NULL, buf, &res, &ec);
  305.         if (res) {
  306.             ScrStatus(res);
  307.         free(res);
  308.         }
  309.         if (ec || rc)return FALSE;
  310.     }
  311.     return TRUE;
  312. }
  313.  
  314. BOOL    CmdSavePrefs(char *args) {
  315.     WINDOW    *window = CurDisplay->ds_Win;
  316.  
  317.     dprefs.left = window->LeftEdge; dprefs.top = window->TopEdge;
  318.     dprefs.width = window->Width; dprefs.height = window->Height;
  319.     WritePrefs();
  320.     ScrStatus("Wrote Prefs");
  321.     return TRUE;
  322. }
  323.  
  324. BOOL    CmdInfo(char *args) {
  325.     ListInfo(CurDisplay);
  326.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  327.     RefreshWindow(TRUE);
  328.     return TRUE;
  329. }
  330.  
  331. BOOL    CmdExecBase(char *args) {
  332.     ListExecBase(CurDisplay);
  333.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  334.     RefreshWindow(TRUE);
  335.     return TRUE;
  336. }
  337.  
  338. BOOL    CmdResources(char *args) {
  339.     ListResources(CurDisplay);
  340.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  341.     RefreshWindow(TRUE);
  342.     return TRUE;
  343. }
  344.  
  345. BOOL    CmdIntrs(char *args) {
  346.     ListIntrs(CurDisplay);
  347.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  348.     RefreshWindow(TRUE);
  349.     return TRUE;
  350. }
  351.  
  352. BOOL    CmdPorts(char *args) {
  353.     ListPorts(CurDisplay);
  354.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  355.     RefreshWindow(TRUE);
  356.     return TRUE;
  357. }
  358.  
  359. BOOL    CmdSymList(char *args) {
  360.     ListSymbols(CurDisplay);
  361.     RefreshWindow(TRUE);
  362.     return TRUE;
  363. }
  364.  
  365. BOOL    CmdTasks(char *args) {
  366.     ListTasks(CurDisplay);
  367.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  368.     RefreshWindow(TRUE);
  369.     return TRUE;
  370. }
  371.  
  372. BOOL    CmdLibs(char *args) {
  373.     ListLibs(CurDisplay);
  374.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  375.     RefreshWindow(TRUE);
  376.     return TRUE;
  377. }
  378.  
  379. BOOL    CmdDevices(char *args) {
  380.     ListDevices(CurDisplay);
  381.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  382.     RefreshWindow(TRUE);
  383.     return TRUE;
  384. }
  385.  
  386. BOOL    CmdMemList(char *args) {
  387.     ListMemList(CurDisplay);
  388.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  389.     RefreshWindow(TRUE);
  390.     return TRUE;
  391. }
  392.  
  393.  
  394. BOOL    CmdDosBase(char *args) {
  395.     ListDosBase(CurDisplay);
  396.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  397.     RefreshWindow(TRUE);
  398.     return TRUE;
  399. }
  400.  
  401. BOOL    CmdProcess(char *args) {
  402.     ListProcess(CurDisplay);
  403.     /*CurDisplay->ds_ListTop = (DLIST *)CurDisplay->ds_List.lh_Head;*/
  404.     RefreshWindow(TRUE);
  405.     return TRUE;
  406. }
  407.  
  408. BOOL    CmdOffsets(char *args) {
  409.     CurDisplay->ds_DisplayOffsets = !CurDisplay->ds_DisplayOffsets;
  410.     RefreshWindow(TRUE);
  411.     return TRUE;
  412. }
  413.  
  414. BOOL    CmdDown(char *args) {
  415.     switch (CurDisplay->ds_DisplayMode) {
  416.         case DISPLAY_DISM:    return DownDism();
  417.         case DISPLAY_SOURCE:    return DownSource();
  418.         case DISPLAY_MIXED:    return DownMixed();
  419.         case DISPLAY_BYTES:    return DownBytes();
  420.         case DISPLAY_WORDS:    return DownWords();
  421.         case DISPLAY_LONGS:    return DownLongs();
  422.         case DISPLAY_HUNKS:    return DownHunks();
  423.         case DISPLAY_BREAK:    return DownBreak();
  424.         case DISPLAY_HELP:    return DownHelp();
  425.         case DISPLAY_SYMBOL:    return DownSymbol();
  426.  
  427.         case DISPLAY_DOSBASE:
  428.         case DISPLAY_PROCESS:
  429.         case DISPLAY_INFO:
  430.         case DISPLAY_EXECBASE:
  431.         case DISPLAY_RESOURCES:
  432.         case DISPLAY_INTRS:
  433.         case DISPLAY_PORTS:
  434.         case DISPLAY_TASKS:
  435.         case DISPLAY_LIBS:
  436.         case DISPLAY_DEVICES:
  437.         case DISPLAY_MEMLIST:    
  438.         case DISPLAY_SYMLIST:
  439.         case DISPLAY_REXXLIST:    return DownList();
  440.  
  441.         default:        break;
  442.     }
  443.     return TRUE;
  444. }
  445.  
  446. BOOL    CmdPageDown(char *args) {
  447.     switch (CurDisplay->ds_DisplayMode) {
  448.         case DISPLAY_DISM:    return PageDownDism();
  449.         case DISPLAY_SOURCE:    return PageDownSource();
  450.         case DISPLAY_MIXED:    return PageDownMixed();
  451.         case DISPLAY_BYTES:    return PageDownHex();
  452.         case DISPLAY_WORDS:    return PageDownHex();
  453.         case DISPLAY_LONGS:    return PageDownHex();
  454.         case DISPLAY_HUNKS:    return DownHunks();
  455.         case DISPLAY_BREAK:    return DownBreak();
  456.         case DISPLAY_HELP:    return DownHelp();
  457.         case DISPLAY_SYMBOL:    return PageDownSymbol();
  458.  
  459.         case DISPLAY_DOSBASE:
  460.         case DISPLAY_PROCESS:
  461.         case DISPLAY_INFO:
  462.         case DISPLAY_EXECBASE:
  463.         case DISPLAY_RESOURCES:
  464.         case DISPLAY_INTRS:
  465.         case DISPLAY_PORTS:
  466.         case DISPLAY_TASKS:
  467.         case DISPLAY_LIBS:
  468.         case DISPLAY_DEVICES:
  469.         case DISPLAY_MEMLIST:    
  470.         case DISPLAY_SYMLIST:
  471.         case DISPLAY_REXXLIST:    return PageDownList();
  472.  
  473.         default:        break;
  474.     }
  475.     return TRUE;
  476. }
  477.  
  478. BOOL    CmdPageUp(char *args) {
  479.     switch (CurDisplay->ds_DisplayMode) {
  480.         case DISPLAY_DISM:    return PageUpDism();
  481.         case DISPLAY_SOURCE:    return PageUpSource();
  482.         case DISPLAY_MIXED:    return PageUpMixed();
  483.         case DISPLAY_BYTES:    return PageUpHex();
  484.         case DISPLAY_WORDS:    return PageUpHex();
  485.         case DISPLAY_LONGS:    return PageUpHex();
  486.         case DISPLAY_HUNKS:    return UpHunks();
  487.         case DISPLAY_BREAK:    return UpBreak();
  488.         case DISPLAY_HELP:    return UpHelp();
  489.         case DISPLAY_SYMBOL:    return PageUpSymbol();
  490.  
  491.         case DISPLAY_DOSBASE:
  492.         case DISPLAY_PROCESS:
  493.         case DISPLAY_INFO:
  494.         case DISPLAY_EXECBASE:
  495.         case DISPLAY_RESOURCES:
  496.         case DISPLAY_INTRS:
  497.         case DISPLAY_PORTS:
  498.         case DISPLAY_TASKS:
  499.         case DISPLAY_LIBS:
  500.         case DISPLAY_DEVICES:
  501.         case DISPLAY_MEMLIST:    
  502.         case DISPLAY_SYMLIST:
  503.         case DISPLAY_REXXLIST:    return PageUpList();
  504.  
  505.         default:        break;
  506.     }
  507.     return TRUE;
  508. }
  509.  
  510. BOOL    CmdUp(char *args) {
  511.     switch (CurDisplay->ds_DisplayMode) {
  512.         case DISPLAY_DISM:    return UpDism();
  513.         case DISPLAY_SOURCE:    return UpSource();
  514.         case DISPLAY_MIXED:    return UpMixed();
  515.         case DISPLAY_BYTES:    return UpBytes();
  516.         case DISPLAY_WORDS:    return UpWords();
  517.         case DISPLAY_LONGS:    return UpLongs();
  518.         case DISPLAY_HUNKS:    return UpHunks();
  519.         case DISPLAY_BREAK:    return UpBreak();
  520.         case DISPLAY_HELP:    return UpHelp();
  521.         case DISPLAY_SYMBOL:    return UpSymbol();
  522.  
  523.         case DISPLAY_DOSBASE:
  524.         case DISPLAY_PROCESS:
  525.         case DISPLAY_INFO:
  526.         case DISPLAY_EXECBASE:
  527.         case DISPLAY_RESOURCES:
  528.         case DISPLAY_INTRS:
  529.         case DISPLAY_PORTS:
  530.         case DISPLAY_TASKS:
  531.         case DISPLAY_LIBS:
  532.         case DISPLAY_DEVICES:
  533.         case DISPLAY_MEMLIST:    
  534.         case DISPLAY_SYMLIST:
  535.         case DISPLAY_REXXLIST:    return UpList();
  536.  
  537.         default:        break;
  538.     }
  539.     return TRUE;
  540. }
  541.  
  542. BOOL    CmdSource(char *args) {
  543.     ULONG    val;
  544.     short    undef;
  545.  
  546.     SetDisplayMode(DISPLAY_SOURCE, 1);
  547.  
  548.     if (*args) {
  549.         val = ParseExp(args, &undef, strlen(args));
  550.         if (undef) return FALSE;
  551.         CurDisplay->ds_WindowTop = val;
  552.         CurDisplay->ds_WindowTopLine = 0;
  553.     }
  554.  
  555.     RefreshWindow(TRUE);
  556.     return TRUE;
  557. }
  558.  
  559.  
  560.  
  561. BOOL    CmdDism(char *args) {
  562.     ULONG    val;
  563.     short    undef;
  564.  
  565.     SetDisplayMode(DISPLAY_DISM, 1);
  566.  
  567.     if (*args) {
  568.         val = ParseExp(args, &undef, strlen(args));
  569.         if (undef) return FALSE;
  570.         CurDisplay->ds_WindowTop = val;
  571.     }
  572.     RefreshWindow(TRUE);
  573.     return TRUE;
  574. }
  575.  
  576.  
  577. BOOL    CmdRegs(char *args) {
  578.  
  579.     CurDisplay->ds_RegFlag = (CurDisplay->ds_RegFlag) ? 0 : 1;
  580.     CurDisplay->ds_RegTouched = TRUE;
  581.     RefreshWindow(TRUE);
  582.     return TRUE;
  583. }
  584.  
  585. BOOL    CmdEval(char *args) {
  586.     ULONG    val;
  587.     short    undef;
  588.     BOOL r = TRUE;
  589.  
  590.     if (*args) {
  591.         val = ParseExp(args, &undef, strlen(args));
  592.         if (undef) {
  593.             r = FALSE;
  594.             ScrStatus("Result undefined");
  595.         } else {
  596.             char buf[128];
  597.  
  598.             OffsetAddressBuf(val, buf);
  599.             ScrStatus("Result %d (0x%08lx) (%s)", val, val, buf);
  600.         }
  601.     }
  602.     return r;
  603. }
  604.  
  605. BOOL    CmdOpen(char *args) {
  606.     DBugDisp *disp, *olddisp;
  607.  
  608.     disp = ScrOpen(FALSE, TRUE, DefaultPubName);
  609.     if(*args && disp) {
  610.         olddisp = CurDisplay;
  611.         CurDisplay = disp;
  612.         DoCommand(args);
  613.         InitCommand();
  614.         ScrCursoff();
  615.         RefreshCommand(TRUE);
  616.         ScrCurson();
  617.         SetDisplayMode(CurDisplay->ds_DisplayMode, 1);  // make this the default for this window
  618.         CurDisplay = olddisp;
  619.     }
  620.     return TRUE;
  621. }
  622.  
  623. BOOL    CmdClose(char *args) {
  624.  
  625.     RequestCloseDisplay(CurDisplay,TRUE);
  626.     return TRUE;
  627. }
  628.  
  629. BOOL    CmdMixed(char *args) {
  630.     ULONG    val;
  631.     short    undef;
  632.  
  633.     SetDisplayMode(DISPLAY_MIXED, 1);
  634.     if (*args) {
  635.         val = ParseExp(args, &undef, strlen(args));
  636.         if (undef) return FALSE;
  637.         CurDisplay->ds_WindowTop = val;
  638.         CurDisplay->ds_WindowTopLine = 0;
  639.     }
  640.     RefreshWindow(TRUE);
  641.     return TRUE;
  642. }
  643.  
  644. BOOL    CmdBytes(char *args) {
  645.     ULONG    val;
  646.     short    undef;
  647.  
  648.     SetDisplayMode(DISPLAY_BYTES, 1);
  649.  
  650.     if (*args) {
  651.         val = ParseExp(args, &undef, strlen(args));
  652.         if (undef) return FALSE;
  653.         CurDisplay->ds_WindowTop = val;
  654.     }
  655.     RefreshWindow(TRUE);
  656.     return TRUE;
  657. }
  658.  
  659. BOOL    CmdWords(char *args) {
  660.     ULONG    val;
  661.     short    undef;
  662.  
  663.     SetDisplayMode(DISPLAY_WORDS, 1);
  664.  
  665.     if (*args) {
  666.         val = ParseExp(args, &undef, strlen(args));
  667.         if (undef) return FALSE;
  668.         CurDisplay->ds_WindowTop = val;
  669.     }
  670.     RefreshWindow(TRUE);
  671.     return TRUE;
  672. }
  673.  
  674. BOOL    CmdLongs(char *args) {
  675.     ULONG    val;
  676.     short    undef;
  677.  
  678.     SetDisplayMode(DISPLAY_LONGS, 1);
  679.  
  680.     if (*args) {
  681.         val = ParseExp(args, &undef, strlen(args));
  682.         if (undef) return FALSE;
  683.         CurDisplay->ds_WindowTop = val;
  684.     }
  685.     RefreshWindow(TRUE);
  686.     return TRUE;
  687. }
  688.  
  689. BOOL    CmdBreakpoint(char *args) {
  690.  
  691.     SetDisplayMode(DISPLAY_BREAK, 0);
  692.     RefreshWindow(TRUE);
  693.     return TRUE;
  694. }
  695.  
  696. BOOL    CmdBP(char *args) {
  697.     ULONG    val;
  698.     short    undef;
  699.  
  700.     if (*args) {
  701.         if (!strnicmp(args, "ALL", 3)) {
  702.             SetAllBreakpoints();
  703.             ScrStatus("Breakpoint table set");
  704.             RefreshAllWindows(TRUE);
  705.             return TRUE;
  706.         }
  707.         val = ParseExp(args, &undef, strlen(args));
  708.         if (undef || !val) val = CurDisplay->ds_WindowTop;
  709.  
  710.         // check if break point is already set
  711.         // if so, clear it
  712.         if(IsBreakpoint(val))return(CmdClear(args));
  713.  
  714.         if (SetBreakpoint(val, 1, BP_SET)) {
  715.             RefreshAllWindows(TRUE);
  716.             ScrStatus("BP set at 0x%08x", val);
  717.             return TRUE;
  718.         }
  719.         else {
  720.             ScrStatus("*** Can't set BP at 0x%08x", val);
  721.             return FALSE;
  722.         }
  723.     }
  724.     ScrStatus("*** Usage: bp {expr}");
  725.     return FALSE;
  726. }
  727.  
  728. BOOL    CmdClear(char *args) {
  729.     ULONG    val;
  730.     short    undef;
  731.  
  732.     if (*args) {
  733.         if (!strnicmp(args, "ALL", 3)) {
  734.             InitBreakpoints();
  735.             ScrStatus("Breakpoint table cleared");
  736.             RefreshAllWindows(TRUE);
  737.             return TRUE;
  738.         }
  739.         val = ParseExp(args, &undef, strlen(args));
  740.         if (undef) return FALSE;
  741.         if (ClearBreakpoint(val)) {
  742.             RefreshAllWindows(TRUE);
  743.             ScrStatus("BP cleared at 0x%08x", val);
  744.             return TRUE;
  745.         }
  746.         else {
  747.             ScrStatus("*** Can't clear BP at 0x%08x", val);
  748.             return FALSE;
  749.         }
  750.     }
  751.     ScrStatus("*** Usage: clear {expr}");
  752.     return FALSE;
  753. }
  754.  
  755. BOOL    CmdHunks(char *args) {
  756.  
  757.     SetDisplayMode(DISPLAY_HUNKS, 0);
  758.     RefreshWindow(TRUE);
  759.     return TRUE;
  760. }
  761.  
  762. BOOL    CmdSymbol(char *args) {
  763.     ULONG    val;
  764.     short    undef;
  765.  
  766.     SetDisplayMode(DISPLAY_SYMBOL, 0);
  767.  
  768.     if (*args) {
  769.         val = ParseExp(args, &undef, strlen(args));
  770.         if (undef) return FALSE;
  771.         CurDisplay->ds_WindowTop = SymbolIndexOfAddr(val);     // pseudo index
  772.     }
  773.     RefreshWindow(TRUE);
  774.     return TRUE;
  775. }
  776.  
  777. static char *casts[3] = { "(BYTE)","(WORD)","(LONG)"};
  778.  
  779.  
  780.  
  781. BOOL    CmdSet(char *args) {
  782.     UBYTE    *adb;
  783.     UWORD   *adw;
  784.     ULONG    *adl;
  785.     ULONG    val=0, addr, address;
  786.     short    undef = 1;
  787.     int i, castsize = 2;
  788.     char *ptr,*ptr1;
  789.  
  790.     if (*args) {
  791.     ptr = args;
  792.     ptr1 = strchr(args,' ');    // split into two strings
  793.     if(ptr1) {
  794.         *ptr1++ = NULL;
  795.         for(i=0; i<3; i++) {  // check for cast operator
  796.         if(!stricmp(casts[i],ptr)) {
  797.             castsize = i;
  798.             // adjust the pointers
  799.             ptr = ptr1;
  800.             if(!(ptr1 = strchr(ptr,' ')))return FALSE;
  801.             *ptr1++ = NULL;    // split the string
  802.             break;
  803.         }
  804.         }
  805.         // check it its a register
  806.             if((strlen(ptr) >= 3) && (ptr[2]==':')) {
  807.          ptr[2]=' ';
  808.          if((addr = (ULONG)RegisterAddress(ptr)))undef = 0;    // yes, its a register
  809.         }
  810.         if(undef)addr = ParseExp(ptr, &undef, strlen(ptr));  // must be an address
  811.         if(!undef) {
  812.             val = ParseExp(ptr1, &undef, strlen(ptr1));
  813.             if (address = ValidMemCheck((ULONG)addr)) {
  814.                 switch (castsize) {
  815.             case 0:
  816.                     adb = (UBYTE *)address;
  817.                     *adb = (BYTE)val;
  818.                     break;
  819.             case 1:
  820.                     adw = (UWORD *)address;
  821.                     *adw = (WORD)val;
  822.                     break;
  823.             case 2:
  824.                     adl = (ULONG *)address;
  825.                     *adl = (LONG)val;
  826.                     break;
  827.  
  828.             default:
  829.                     return FALSE;
  830.             }
  831.             ScrStatus("%08X set to %X",addr,val);
  832.             RefreshAllWindows(FALSE);
  833.                 return TRUE;
  834.         }
  835.         ScrStatus("*** Can't set %08X to %X",addr,val);
  836.         return FALSE;
  837.         }
  838.     }
  839.     }
  840.     ScrStatus("*** Usage: set {expr} {value}");
  841.     return FALSE;
  842. }
  843.  
  844. BOOL CmdAgain(char *args) {
  845.     return DoCommand(lastCommand);
  846. }
  847.  
  848. BOOL CmdChangeWindow(char *args) {
  849. char *ptr, *ptr1;
  850. int size[4] = {-1, -1, -1, -1};
  851. int i = -1;
  852.  
  853.     if(((struct Library *)SysBase)->lib_Version >= 36) {
  854.  
  855.         ptr = args;
  856.         while ((++i < 4) && *ptr) {
  857.         size[i]=strtol(ptr,&ptr1,10);
  858.         ptr = ptr1;
  859.         }
  860.         if(i == 4) {
  861.         ChangeWindowBox(CurDisplay->ds_Win,size[0],size[1],size[2],size[3]);
  862.         ScrStatus("Window repositioned\n");
  863.         return TRUE;
  864.         }
  865.         ScrStatus("*** Usage: ChangeWindow {left} {top} {width} {height}");
  866.     }
  867.     return FALSE;
  868. }
  869.  
  870.  
  871. BOOL    StepTargetRange(ULONG addressLow, ULONG addressHi) {
  872.  
  873.     // step within the address range given
  874.     // (execute at least once, though)
  875.     do {
  876.         CopyLastState();
  877.         programSR |= 0x8000;
  878.         EnterProgram();
  879.         programSR &= 0x7fff;
  880.     } while((programPC >=  addressLow) && (programPC <= addressHi));
  881.  
  882.     if (CurDisplay->ds_DisplayMode > DISPLAY_MIXED)
  883.         SetDisplayMode(CurDisplay->ds_PreferedMode, 0);
  884.  
  885.     if (programState == STATE_TRACE)programState = STATE_STEPPED;
  886.  
  887.     if ((programPC <= CurDisplay->ds_WindowTop) || (programPC >= CurDisplay->ds_WindowBot)) {
  888.         CurDisplay->ds_WindowTop = programPC;
  889.         ForceFullRefresh = 1;
  890.     }
  891.     return (programState == STATE_STEPPED);
  892. }
  893.  
  894. BOOL    StepTarget(void) {
  895.  
  896.     CopyLastState();
  897.     programSR |= 0x8000;
  898.     EnterProgram();
  899.     programSR &= 0x7fff;
  900.  
  901.     if (CurDisplay->ds_DisplayMode > DISPLAY_MIXED)
  902.         SetDisplayMode(CurDisplay->ds_PreferedMode, 0);
  903.  
  904.     if (programState == STATE_TRACE)programState = STATE_STEPPED;
  905.     if ((programPC <= CurDisplay->ds_WindowTop) || (programPC >= CurDisplay->ds_WindowBot)) {
  906.         CurDisplay->ds_WindowTop = programPC;
  907.         ForceFullRefresh = 1;
  908.     }
  909.  
  910.  
  911.     return (programState == STATE_STEPPED);
  912. }
  913.  
  914. BOOL    CmdRStep(char *args)
  915. {
  916.     RStepFlag = !RStepFlag;
  917.     if(!RStepFlag)ScrStatus("Library step over off");
  918.     else ScrStatus("Library step over on");
  919.     return TRUE;
  920. }
  921.  
  922.  
  923. // If an argument given, will do a range single step 
  924.  
  925. BOOL    CmdStep(char *args) {
  926.     BOOL    result, fullRefresh = FALSE;
  927.     ULONG endrange = 0;
  928.     short undef;
  929.  
  930.     // process the range argument
  931.     if(*args) {
  932.         // stop before the specified instruction
  933.         endrange = ParseExp(args, &undef, strlen(args)) - 2;
  934.         if (undef) endrange = 0;
  935.     }
  936.     switch (CurDisplay->ds_PreferedMode) {
  937.         case DISPLAY_SOURCE: {
  938.             ULONG address = programPC, line = 0;
  939.             WORD type, breakflag = 0;
  940.  
  941.             if(CurrentMixedLine(&address,&line,NULL) == MIXTYPE_SOURCE) {
  942.             // find end of address range for the target range
  943.             while((type = NextMixedLine(&address,&line,NULL)) == MIXTYPE_SOURCE);
  944.  
  945.             while(type == MIXTYPE_DISM) {
  946.                 endrange = address;
  947.                 while(NextMixedLine(&address,&line,NULL) == MIXTYPE_DISM) {
  948.                 endrange = address;
  949.                 }
  950.                 if(endrange >= programPC) {
  951.                     if(!RStepFlag)result = StepTargetRange(programPC,endrange);
  952.                 else result = RStepTargetRange(programPC,endrange);
  953.                 address = programPC;
  954.                 line = 0;
  955.                     if(CurrentMixedLine(&address,&line,NULL) == MIXTYPE_DISM)continue;
  956.                 breakflag = TRUE; // switch break
  957.                     break;
  958.                 }
  959.             }
  960.             if(breakflag)break;
  961.             }
  962. #if 0
  963.             //  This doesn't really work all that well
  964.             //  So its gone
  965.  
  966.     DEBUG    *debug;
  967.             while (1) {
  968.                 if (!OverTarget()) { result = FALSE; break; }
  969.                 debug = FindDebug(programPC);
  970.                 if (!debug)
  971.                     result = FALSE;
  972.                 else {
  973.                     if (FindSource(debug, programPC)) { result = TRUE; break; }
  974.                 }
  975.             }
  976.             break;
  977. #endif
  978.  
  979.         }
  980.         case DISPLAY_MIXED:
  981.         case DISPLAY_DISM:
  982.             if(endrange) {
  983.                 if(!RStepFlag)result = StepTargetRange(programPC,endrange);
  984.                 else result = RStepTargetRange(programPC,endrange);
  985.             }
  986.             else {
  987.                 if(!RStepFlag)result = StepTarget();
  988.                 else result = RStepTarget();
  989.             }
  990.             break;
  991.     }
  992.     RefreshAllWindows(FALSE);
  993.     return result;
  994. }
  995.  
  996. BOOL    OverTargetRange(ULONG addressLow, ULONG addressHi) {
  997.     char    buf[128];
  998.     ULONG    size, twp;
  999.     UWORD    *pw;
  1000.  
  1001.     do {
  1002.     pw = (UWORD *)programPC;
  1003.     // over at a forward branch is treated as a regular StepTarget()
  1004.     // Check for Bcc instruction
  1005.     if (((*pw & 0xf000) == 0x6000) && ((*pw & 0xff00) != 0x6100)) {    
  1006.         if ((*pw & 0xff) == 0xff) {        // 32-bit displacement (020+ only)
  1007.             ULONG *pl = (ULONG *)&pw[1];
  1008.             if (*pl > 0) {
  1009.             StepTarget();
  1010.                 continue;
  1011.             }
  1012.         }
  1013.         else if ((*pw & 0xff) == 0x00) {    // 16-bit displacement
  1014.             UWORD *lpw = (UWORD *)&pw[1];
  1015.             if (*lpw > 0) {
  1016.             StepTarget();
  1017.                 continue;
  1018.             }
  1019.         }
  1020.         else {                    // 8-bit displacement
  1021.             if ((*pw & 0xff) < 0x80) {
  1022.             StepTarget();
  1023.                 continue;
  1024.             }
  1025.         }
  1026.     }
  1027.     size = Disassemble(programPC, programPC, buf);
  1028.     // over at RTS, or JMP is treated as a regular StepTarget()
  1029.     if (!strnicmp(buf, "RTS", 3) || !strnicmp(buf, "JMP", 3)) {
  1030.         StepTarget();
  1031.         continue;
  1032.     }
  1033.  
  1034.     // set temp breakpoint at instruction after current PC
  1035.         if(TypeOfMem((UBYTE *)((ULONG)programPC)+size)) {
  1036.         SetTempBreakpoint(programPC+size);
  1037.         if (!GoTarget()) return FALSE;
  1038.     }
  1039.     else {
  1040.         twp = programPC+size;
  1041.             while(twp != programPC) {
  1042.         if(!StepTarget()) {
  1043.             if(programState == STATE_EXITED)return FALSE;
  1044.             break;
  1045.         }
  1046.         }
  1047.         if(programState == STATE_STEPPED)programState = STATE_STEPPEDOVER;
  1048.     }
  1049.     if (programPC < CurDisplay->ds_WindowTop || programPC > CurDisplay->ds_WindowBot) {
  1050.         CurDisplay->ds_WindowTop = programPC;
  1051.         ForceFullRefresh = 1;
  1052.     }
  1053.     } while ((programPC >=  addressLow) && (programPC <= addressHi));
  1054.     return (programState == STATE_STEPPEDOVER);
  1055. }
  1056.  
  1057. BOOL    OverTarget(void) {
  1058.     char    buf[128];
  1059.     ULONG    size, twp;
  1060.     UWORD    *pw = (UWORD *)programPC;
  1061.     // over at a forward branch is treated as a regular StepTarget()
  1062.     if (((*pw & 0xf000) == 0x6000) && ((*pw & 0xff00) != 0x6100)) {    // Bcc instruction
  1063.     if ((*pw & 0xff) == 0xff) {        // 32-bit displacement (020+ only)
  1064.         ULONG    *pl = (ULONG *)&pw[1];
  1065.         if (*pl > 0) return StepTarget();
  1066.     }
  1067.     else if ((*pw & 0xff) == 0x00) {    // 16-bit displacement
  1068.         UWORD    *lpw = (UWORD *)&pw[1];
  1069.         if (*lpw > 0) return StepTarget();
  1070.     }
  1071.     else {                    // 8-bit displacement
  1072.         if ((*pw & 0xff) < 0x80) {
  1073.         return StepTarget();
  1074.         }
  1075.     }
  1076.     }
  1077.  
  1078.     size = Disassemble(programPC, programPC, buf);
  1079.     // over at RTS, or JMP is treated as a regular StepTarget()
  1080.     if (!strnicmp(buf, "RTS", 3) || !strnicmp(buf, "JMP", 3)) return StepTarget();
  1081.  
  1082.     // set temp breakpoint at instruction after current PC
  1083.         if(TypeOfMem((UBYTE *)((ULONG)programPC)+size)) {
  1084.         SetTempBreakpoint(programPC+size);
  1085.         if (!GoTarget()) return FALSE;
  1086.     }
  1087.     else {
  1088.         twp = programPC+size;
  1089.             while(twp != programPC) {
  1090.         if(!StepTarget()) {
  1091.             if(programState == STATE_EXITED)return FALSE;
  1092.             break;
  1093.         }
  1094.         }
  1095.         if(programState == STATE_STEPPED)programState = STATE_STEPPEDOVER;
  1096.     }
  1097.     if ((programPC <= CurDisplay->ds_WindowTop) || (programPC >= CurDisplay->ds_WindowBot)) {
  1098.         CurDisplay->ds_WindowTop = programPC;
  1099.         ForceFullRefresh = 1;
  1100.     }
  1101.  
  1102.     return (programState == STATE_STEPPEDOVER);
  1103. }
  1104.  
  1105. // Rom Step Target
  1106. // Automatically steps over library calls
  1107. // otherwise single steps
  1108.  
  1109. BOOL    RStepTarget(void) {
  1110.     char    buf[128];
  1111.     ULONG    size, twp;
  1112.  
  1113.     size = Disassemble(programPC, programPC, buf);
  1114.     if (strnicmp(buf, "JSR", 3))return StepTarget();
  1115.     if(!strchr(buf,'-') || !strstr(buf,"(A6)"))return StepTarget();
  1116.  
  1117.     // well, its a JSR negative offset through A6, so lets skip over
  1118.  
  1119.     // set temp breakpoint at instruction after current PC
  1120.     if(TypeOfMem((UBYTE *)((ULONG)programPC)+size)) {
  1121.         SetTempBreakpoint(programPC+size);
  1122.         if (!GoTarget()) return FALSE;
  1123.     }
  1124.     else {
  1125.     // we're in rom;  setting the breakpoint will not work well
  1126.         twp = programPC+size;
  1127.         while(twp != programPC) {
  1128.         if(!StepTarget()) {
  1129.             if(programState == STATE_EXITED)return FALSE;
  1130.         break;
  1131.         }
  1132.     }
  1133.         if(programState == STATE_STEPPED)programState = STATE_STEPPEDOVER;
  1134.     }
  1135.     if (programPC <= CurDisplay->ds_WindowTop || programPC >= CurDisplay->ds_WindowBot) {
  1136.     CurDisplay->ds_WindowTop = programPC;
  1137.     ForceFullRefresh = 1;
  1138.     }
  1139.  
  1140.     return (programState == STATE_STEPPEDOVER);
  1141. }
  1142.  
  1143.  
  1144.  
  1145. BOOL    RStepTargetRange(ULONG addressLow, ULONG addressHi) {
  1146.     char    buf[128];
  1147.     ULONG    size, twp;
  1148.  
  1149.     do {
  1150.     size = Disassemble(programPC, programPC, buf);
  1151.  
  1152.     if (strnicmp(buf, "JSR", 3))return StepTarget();
  1153.     if(!strchr(buf,'-') || !strstr(buf,"(A6)"))return StepTarget();
  1154.  
  1155.     // well, its a JSR negative offset through A6, so lets skip over
  1156.  
  1157.     // set temp breakpoint at instruction after current PC
  1158.         if(TypeOfMem((UBYTE *)((ULONG)programPC)+size)) {
  1159.         SetTempBreakpoint(programPC+size);
  1160.         if (!GoTarget()) return FALSE;
  1161.     }
  1162.     else {
  1163.         twp = programPC+size;
  1164.             while(twp != programPC) {
  1165.             if(!StepTarget()) {
  1166.                 if(programState == STATE_EXITED)return FALSE;
  1167.             break;
  1168.         }
  1169.         }
  1170.             if(programState == STATE_STEPPED)programState = STATE_STEPPEDOVER;
  1171.     }
  1172.     if (programPC < CurDisplay->ds_WindowTop || programPC > CurDisplay->ds_WindowBot) {
  1173.         CurDisplay->ds_WindowTop = programPC;
  1174.         ForceFullRefresh = 1;
  1175.     }
  1176.     } while ((programPC >=  addressLow) && (programPC <= addressHi));
  1177.  
  1178.     return (programState == STATE_STEPPEDOVER);
  1179. }
  1180.  
  1181. BOOL    CmdOver(char *args) {
  1182.     BOOL    result;
  1183.     ULONG  endrange = 0;
  1184.     short undef;
  1185.  
  1186.     // process the range argument
  1187.     if(*args) {
  1188.         // stop before the specified instruction
  1189.         endrange = ParseExp(args, &undef, strlen(args)) - 2;
  1190.         if (undef) endrange = 0;
  1191.     }
  1192.  
  1193.     switch (CurDisplay->ds_PreferedMode) {
  1194.         case DISPLAY_SOURCE: {
  1195.             ULONG address = programPC, line = 0;
  1196.             WORD type, breakflag = 0;
  1197.  
  1198.             type = CurrentMixedLine(&address,&line,NULL);
  1199.             if (type == 0)type = NextMixedLine(&address, &line, NULL);
  1200.             if(type == MIXTYPE_SOURCE) {
  1201.             // find end of address range for the target range
  1202.             while((type = NextMixedLine(&address,&line,NULL)) == MIXTYPE_SOURCE);
  1203.  
  1204.             while(type == MIXTYPE_DISM) {
  1205.                 endrange = address;
  1206.                 while(NextMixedLine(&address,&line,NULL) == MIXTYPE_DISM)endrange = address;
  1207.                 if(endrange >= programPC) {
  1208.                     result = OverTargetRange(programPC,endrange);
  1209.  
  1210.                 // find the next source line (if not on a source line)
  1211.                 // and execute to it
  1212.                 address = programPC;    // on a source line yet ?
  1213.                 line = 0;
  1214.                     type = CurrentMixedLine(&address,&line,NULL);
  1215.                 }
  1216.             }
  1217.                 if(type == MIXTYPE_SOURCE)break;
  1218.             }
  1219.             // drop through to mixed case
  1220.             endrange = 0;
  1221.         }
  1222.         case DISPLAY_MIXED:
  1223.         case DISPLAY_DISM:
  1224.             if(endrange)result = OverTargetRange(programPC,endrange);
  1225.             else result = OverTarget();
  1226.             break;
  1227.     }
  1228.     RefreshAllWindows(FALSE);
  1229.     return result;
  1230. }
  1231.  
  1232. BOOL    CmdRefresh(char *args) {
  1233.  
  1234.     RefreshWindow(TRUE);
  1235. }
  1236.  
  1237.  
  1238. BOOL    CmdReset(char *args) {
  1239.     ULONG    i;
  1240.  
  1241.     if (programState != STATE_RESET && programState != STATE_EXITED &&
  1242.         (LookupSymbol("@exit", &i) || LookupSymbol("_exit", &i))) {
  1243.         programPC = i;
  1244.         GoTarget();
  1245.         if (programState != STATE_EXITED) { 
  1246.             RefreshWindow(TRUE); 
  1247.             return FALSE; 
  1248.         }
  1249.     }
  1250.     ResetTarget();
  1251.     RefreshWindow(TRUE);
  1252.     ScrStatus("Target Reset");
  1253.     return TRUE;
  1254. }
  1255.  
  1256. BOOL    GoTarget(void) {
  1257.  
  1258.     if (IsBreakpoint(programPC)) {
  1259.         programSR |= 0x8000; 
  1260.         EnterDebugger(); 
  1261.         programSR &= 0x7fff;
  1262.         if (programState != STATE_TRACE) return FALSE;
  1263.     }
  1264.     InstallBreakpoints();
  1265.  
  1266.     CopyLastState();
  1267.     EnterProgram();
  1268.     CheckBreakpoints();
  1269.     
  1270.     if(CurDisplay) {
  1271.         if (CurDisplay->ds_DisplayMode > DISPLAY_MIXED)
  1272.             SetDisplayMode(CurDisplay->ds_PreferedMode, 0);
  1273.  
  1274.         if (programPC < CurDisplay->ds_WindowTop || programPC > CurDisplay->ds_WindowBot)
  1275.         CurDisplay->ds_WindowTop = programPC;
  1276.     }
  1277.     return TRUE;
  1278. }
  1279.  
  1280. Local void    CopyLastState(void) {
  1281.     lastState = programState;
  1282.     lastSR = programSR;
  1283.     lastPC = programPC;
  1284.     lastD0 = programD0; lastD1 = programD1; lastD2 = programD2; lastD3 = programD3;
  1285.     lastD4 = programD4; lastD5 = programD5; lastD6 = programD6; lastD7 = programD7;
  1286.     lastA0 = programA0; lastA1 = programA1; lastA2 = programA2; lastA3 = programA3;
  1287.     lastA4 = programA4; lastA5 = programA5; lastA6 = programA6; lastA7 = programA7;
  1288. }
  1289.  
  1290. BOOL    CmdGo(char *args) {
  1291.     char    symbol[128];
  1292.     char    *pd;
  1293.     ULONG    addr;
  1294.  
  1295.     while (*args) {
  1296.         while (*args == ' ' || *args == '\t') args++;
  1297.         if (*args) {
  1298.             WORD    undef;
  1299.  
  1300.             pd = &symbol[0];
  1301.             while (*args && *args != ' ' && *args != '\t') *pd++ = *args++;
  1302.             *pd = '\0';
  1303.             addr = ParseExp(symbol, &undef, strlen(symbol));
  1304.             if (undef) return FALSE;
  1305.             if (!SetBreakpoint(addr, 1, BP_GROUP)) return FALSE;
  1306.         }
  1307.     }
  1308.     GoTarget();
  1309. //    RefreshWindow(FALSE);
  1310.     RefreshAllWindows(FALSE);    // just in case a breakpoint was hit.
  1311.                     // probably should limit refresh to
  1312.                     // source, asm, mixed, and bp wondows
  1313.     return TRUE;
  1314. }
  1315.  
  1316. BOOL    CmdQuit(char *args) {
  1317.     ULONG    i;
  1318.  
  1319.     if (programState != STATE_RESET && programState != STATE_EXITED) {
  1320.         if (LookupSymbol("@exit", &i)) {
  1321.             programD0 = RETURN_FAIL;
  1322.             programPC = i;
  1323.             GoTarget();
  1324.             if (programState != STATE_EXITED) { 
  1325.                 if(CurDisplay)RefreshWindow(TRUE); 
  1326.                 return FALSE; 
  1327.             }
  1328.         }
  1329.         else if (LookupSymbol("_exit", &i)) {
  1330.             ULONG    *pl = (ULONG *)programA7;
  1331.             --pl;
  1332.             *pl = RETURN_FAIL;
  1333.             programA7 = (ULONG)pl;
  1334.             programPC = i;
  1335.             GoTarget();
  1336.             if (programState != STATE_EXITED) { 
  1337.                 if(CurDisplay) {
  1338.                 RefreshWindow(TRUE); 
  1339.                 }
  1340.                 return FALSE; 
  1341.             }
  1342.             // pick up return code and load into D0
  1343.             programD0 = *pl;
  1344.         }
  1345.     }
  1346.     printf("\n*** %s Exited, code %d\n", targetName, programD0);
  1347.     exit(0);
  1348.     return TRUE;
  1349. }
  1350.  
  1351. BOOL    CmdHelp(char *args) {
  1352.  
  1353.     if (*args == 0 && CurDisplay->ds_DisplayMode == DISPLAY_HELP) {
  1354.         SetDisplayMode(CurDisplay->ds_PreferedMode, 0);
  1355.     } else {
  1356.         SetDisplayMode(DISPLAY_HELP, 0);
  1357.         if (CurDisplay->ds_WindowTop < 0)
  1358.             CurDisplay->ds_WindowTop = 0;
  1359.         if (CurDisplay->ds_WindowTop > arysize(commandTable) + arysize(HelpTable))
  1360.             CurDisplay->ds_WindowTop = arysize(commandTable) + arysize(HelpTable) - 1;
  1361.     }
  1362.     RefreshWindow(TRUE);
  1363.     return TRUE;
  1364. }
  1365.  
  1366. // ************
  1367.  
  1368. BOOL    CmdWatchClear(char *args) {
  1369.  
  1370.         InitWatchpoints();
  1371.     RefreshWindow(TRUE);
  1372.     return TRUE;
  1373. }
  1374.  
  1375.  
  1376. BOOL    CmdWatchBytes(char *args) {
  1377.     char    symbol[128];
  1378.     char    *pd;
  1379.     BOOL    fullRefresh = FALSE;
  1380.  
  1381.     while (*args) {
  1382.         while (*args == ' ' || *args == '\t') args++;
  1383.         if (*args) {
  1384.             pd = &symbol[0];
  1385.             while (*args && *args != ' ' && *args != '\t') *pd++ = *args++;
  1386.             *pd = '\0';
  1387.             if (IsWatchpoint(symbol)) {
  1388.                 if (!ClearWatchpoint(symbol)) return FALSE;
  1389.                 fullRefresh = TRUE;
  1390.             }
  1391.             else {
  1392.                 if (!SetWatchpoint(symbol, WP_BYTES)) return FALSE;
  1393.             }
  1394.             fullRefresh = TRUE;
  1395.         }
  1396.     }
  1397.     RefreshWindow(fullRefresh);
  1398.     return TRUE;
  1399. }
  1400.  
  1401. BOOL    CmdWatchWords(char *args) {
  1402.     char    symbol[128];
  1403.     char    *pd;
  1404.     BOOL    fullRefresh = FALSE;
  1405.  
  1406.     while (*args) {
  1407.         while (*args == ' ' || *args == '\t') args++;
  1408.         if (*args) {
  1409.             pd = &symbol[0];
  1410.             while (*args && *args != ' ' && *args != '\t') *pd++ = *args++;
  1411.             *pd = '\0';
  1412.             if (IsWatchpoint(symbol)) {
  1413.                 if (!ClearWatchpoint(symbol)) return FALSE;
  1414.                 fullRefresh = TRUE;
  1415.             }
  1416.             else if (!SetWatchpoint(symbol, WP_WORDS)) return FALSE;
  1417.             fullRefresh = TRUE;
  1418.         }
  1419.     }
  1420.     RefreshWindow(fullRefresh);
  1421.     return TRUE;
  1422. }
  1423.  
  1424. BOOL    CmdWatchLongs(char *args) {
  1425.     char    symbol[128];
  1426.     char    *pd;
  1427.     BOOL    fullRefresh = FALSE;
  1428.  
  1429.     while (*args) {
  1430.         while (*args == ' ' || *args == '\t') args++;
  1431.         if (*args) {
  1432.             pd = &symbol[0];
  1433.             while (*args && *args != ' ' && *args != '\t') *pd++ = *args++;
  1434.             *pd = '\0';
  1435.             if (IsWatchpoint(symbol)) {
  1436.                 if (!ClearWatchpoint(symbol)) return FALSE;
  1437.                 fullRefresh = TRUE;
  1438.             }
  1439.             else if (!SetWatchpoint(symbol, WP_LONGS)) return FALSE;
  1440.             fullRefresh = TRUE;
  1441.         }
  1442.     }
  1443.     RefreshWindow(fullRefresh);
  1444.     return TRUE;
  1445. }
  1446.  
  1447. // ************
  1448.  
  1449. BOOL    UpHelp(void) {
  1450.     if (CurDisplay->ds_WindowTop) {
  1451.         CurDisplay->ds_LastRefreshTop = --CurDisplay->ds_WindowTop;
  1452.         ScrScrolldown();
  1453.         RefreshHelp(1, 0, CurDisplay->ds_WindowTop);
  1454.     }
  1455.     return TRUE;
  1456. }
  1457.  
  1458. BOOL    DownHelp(void) {
  1459.     CurDisplay->ds_LastRefreshTop = ++CurDisplay->ds_WindowTop;
  1460.     ScrScrollup();
  1461.     RefreshHelp(1, 0, CurDisplay->ds_WindowTop + ScrMainBodyRange(NULL,NULL) - 1);
  1462. }
  1463.  
  1464.  
  1465. WORD    RefreshHelp(WORD maxLines, BOOL fullRefresh, LONG index) {
  1466.     WORD    count = 0;
  1467.  
  1468.     do_scroller();
  1469.     if (fullRefresh) {
  1470.         SetTitle(NULL,NULL);
  1471. #if 0
  1472.         ScrInverse();
  1473.         ScrPrintf("ON-LINE HELP");
  1474. #endif
  1475.  
  1476.         if(CurDisplay->ds_RegFlag) {
  1477.         Newline();
  1478.         ++count;
  1479.         if (--maxLines <= 0)return count;
  1480.         }
  1481.     }
  1482.     ScrPlain();
  1483.  
  1484.     while (maxLines > 0 && index < arysize(commandTable) + arysize(HelpTable)) {
  1485.         if (index >= 0) {
  1486.         if (index >= arysize(commandTable)) {
  1487.             ScrPuts(HelpTable[index-arysize(commandTable)]);
  1488.         } 
  1489.         else {
  1490.             ScrPuts(commandTable[index].helpText);
  1491.         }
  1492.         Newline();
  1493.         --maxLines;
  1494.         ++count;
  1495.         }
  1496.         ++index;
  1497.     }
  1498.     return count;
  1499. }
  1500.  
  1501. int HelpSize(void)
  1502. {
  1503. return arysize(commandTable) + arysize(HelpTable) + 4;
  1504. }
  1505.  
  1506. BOOL    CmdAlias(char *args)
  1507. {
  1508.     short i;
  1509.  
  1510.     for (i=0; commandTable[i].command; i++) {
  1511.         if (!strnicmp(commandTable[i].command, args, commandTable[i].commandLen)) {
  1512.             dprefs.alias[i] = 1;
  1513.             return(TRUE);
  1514.         }
  1515.     }
  1516.     return(FALSE);
  1517. }
  1518.  
  1519. BOOL    CmdUnAlias(char *args)
  1520. {
  1521.     short i;
  1522.  
  1523.     for (i=0; commandTable[i].command; i++) {
  1524.         if (!strnicmp(commandTable[i].command, args, commandTable[i].commandLen)) {
  1525.             dprefs.alias[i] = 0;
  1526.             return(TRUE);
  1527.         }
  1528.     }
  1529.     return(FALSE);
  1530. }
  1531.  
  1532.  
  1533.  
  1534. BOOL CmdJump(char *args)
  1535. {
  1536. struct Screen *scr;
  1537. DBugDisp *disp, *olddisp;
  1538.  
  1539.     // jump only works in 2.0
  1540.     if(((struct Library *)SysBase)->lib_Version >= 36) {
  1541.  
  1542.         if(! *args) {        // we were not given a name to jump to
  1543.                 // so lets go to next pub screen
  1544.         if(!(scr=CurDisplay->ds_Win->WScreen))return FALSE;
  1545.         if(!NextPubScreen(scr,DefaultPubName))return FALSE;
  1546.     }
  1547.         else strcpy(DefaultPubName,args);
  1548.     RequestCloseDisplay(CurDisplay,TRUE);
  1549.     if(disp = ScrOpen(FALSE, TRUE, DefaultPubName)) {
  1550.         olddisp = CurDisplay;
  1551.         CurDisplay = disp;
  1552.         InitCommand();
  1553.         ScrCursoff();
  1554.  
  1555.         ScrStatus("Jumped");
  1556.         RefreshCommand(-1);
  1557.     
  1558.             ScrCurson();
  1559.         CurDisplay = olddisp;
  1560.         return TRUE;
  1561.     }
  1562.     return FALSE;
  1563.     }
  1564. }
  1565.  
  1566.  
  1567. BOOL CmdTitle(char *args)
  1568. {
  1569. char *ptr;
  1570. int n;
  1571.  
  1572.     if(ptr = strchr(args,' ')) {    // if there is a slot
  1573.     *ptr++ = NULL;
  1574.     if((n = FindSlot(args)) >= 0) {
  1575.             if(*ptr) {    // if there is a title given
  1576.             set_menu_item(n,NM_TITLE,ptr,"","");
  1577.         return TRUE;
  1578.         }
  1579.     }
  1580.     }
  1581.     return FALSE;
  1582. }
  1583.  
  1584. BOOL CmdItem(char *args)
  1585. {
  1586. return ProcessMenuItem(args,NM_ITEM);
  1587. }
  1588.  
  1589. BOOL CmdSubItem(char *args)
  1590. {
  1591. return ProcessMenuItem(args,NM_SUB);
  1592. }
  1593.  
  1594. BOOL CmdBar(char *args)
  1595. {
  1596. int n;
  1597.  
  1598.     if((n = FindSlot(args)) >= 0)set_menu_item(n,NM_BAR,"","","");
  1599.     return(TRUE);
  1600. }
  1601.  
  1602. BOOL CmdEnd(char *args)
  1603. {
  1604. int n;
  1605.  
  1606.     if((n = strtol(args,NULL,10)) >= 0)set_menu_item(n,NM_END,"","","");
  1607.     return(TRUE);
  1608. }
  1609.  
  1610. BOOL CmdMenus(char *args)
  1611. {
  1612.     return enable_menus();
  1613. }
  1614.  
  1615. // ************
  1616.  
  1617. char    *SkipBlanks(char *s) { while (*s == ' ' || *s == '\t') s++; return s; }
  1618.  
  1619. BOOL    DoCommand(char *command) {
  1620.     ULONG    val;
  1621.     short    i, undef, j = 2;
  1622.     BOOL res;
  1623.     UBYTE *ptr;
  1624.  
  1625.     oldcol = 0xFFFE;    // cancel a possible double click
  1626.     if(! *command) {
  1627.         ScrStatus("Ready");    // don't bother to search, they just hit a return
  1628.         return TRUE;
  1629.     }
  1630.     ptr = command;
  1631.     while (j--) {
  1632.     for (i=0; commandTable[i].command; i++) {
  1633.         if (!strnicmp(commandTable[i].command, ptr, commandTable[i].commandLen)) {
  1634.             if(dprefs.alias[i]) {
  1635.                 // try to run the correct Arexx script
  1636.                 res = CmdRexx(ptr);
  1637.                 ShortStatus(1,ptr);
  1638.                 return res;
  1639.             }
  1640.             ShortStatus(0,ptr);
  1641.             if(j) ptr = &command[commandTable[i].commandLen];
  1642.             else ptr = command;
  1643.             return (*commandTable[i].func)(SkipBlanks(ptr));
  1644.         }
  1645.     }
  1646.  
  1647.     // not found in table
  1648.     if(j <= 0)break;    // second time through
  1649.  
  1650.     // not found in commandTable.  Maybe it's an "implied display" command (expression only)
  1651.  
  1652.  
  1653.     val = ParseExp(command, &undef, strlen(command));
  1654.     if (!undef) {
  1655.         SetDisplayMode(CurDisplay->ds_PreferedMode, 0);
  1656.         CurDisplay->ds_WindowTop = val;
  1657.         ScrStatus("Result is %0X",val);
  1658.         RefreshWindow(TRUE);
  1659.         return TRUE;
  1660.     } 
  1661.  
  1662.     // allow the argument to be specified first (for convenience in entering commands)
  1663.     if (ptr = strrchr(command,' ')) {
  1664.         *ptr++ = 0;     // split the string
  1665.     }
  1666.     else break;
  1667.     }
  1668.     // hm, see if its an arexx command
  1669.     ShortStatus(2,command);    // reset the display
  1670.     if(CmdRexx(command)) return TRUE;
  1671.     
  1672.     // if its here, its not a command
  1673.     ScrStatus("*** Invalid Command: '%s'", command);
  1674.     return FALSE;
  1675. }
  1676.  
  1677.  
  1678. //    void *msg;        /*    RexxMsg structure if we need it     */
  1679. //    struct MsgPort *port;    /*    MsgPort structure if we need it     */
  1680. //    char *arg0;        /*    arg0                    */
  1681. //    char **pres;        /*    where to put our result if rc==0    */
  1682.  
  1683. long    DoRexxCommand(void *msg, MPORT *port, char *arg0, char **pres) {
  1684.     WORD    i;
  1685.     long res = 5;
  1686.  
  1687.         memset(RexxReplyString,0,MAX_REXX_REPLY);
  1688.       ShortStatus(2,arg0);
  1689.         ScrCursoff();
  1690.  
  1691.     for (i=0; commandTable[i].command; i++) {
  1692.         if (!strnicmp(commandTable[i].command, arg0, commandTable[i].commandLen)) {
  1693.             if ((*commandTable[i].func)(SkipBlanks(&arg0[commandTable[i].commandLen])))
  1694.                 res = 0;
  1695.             else res = 10;
  1696.             *pres = RexxReplyString;
  1697.             break;
  1698.         }
  1699.     }
  1700.     RefreshCommand(TRUE);
  1701.     ScrCurson();
  1702.     return res;    // unrecognized command
  1703. }
  1704.  
  1705.  
  1706.  
  1707. // produce a shortened command status display
  1708. void ShortStatus(int mode, char *command)
  1709. {
  1710. char buf[128], *ptr , *s;
  1711.  
  1712. strcpy(buf,command);
  1713. if(ptr = strchr(buf,' '))*ptr=NULL;    // shorten to just the command
  1714.  
  1715. if(mode == 0)s = "Command";
  1716. else if(mode == 1) s = "Alias";
  1717. else s = "Rexx";
  1718.  
  1719. ScrStatus("%s '%s'",s,buf);
  1720. }
  1721.  
  1722.  
  1723. #if 0
  1724. Prototype void kprintline(char *string);
  1725. void kprintline(char *string)
  1726. {
  1727. kprintf("[");
  1728. while(*string && (*string != '\n'))kprintf("%lc",*string++);
  1729. kprintf("]\n");
  1730. }
  1731. #endif
  1732.  
  1733. #if 0
  1734. Prototype void kprintlen(char *string, int len);
  1735. void kprintlen(char *string, int len)
  1736. {
  1737. kprintf("[");
  1738. while(*string && (*string != '\n') && len--)kprintf("%lc",*string++);
  1739. kprintf("]\n");
  1740. }
  1741. #endif
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.